<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Post extends CI_Model {

	function __construct() {
		parent::__construct();
	}
	/*function do_excerpt($string) {
			//preg_split('/<!-- more -->/', $string, $limit, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
		}*/


	function get_post($pid) {
		$this->db->start_cache();
		$this->db->select('pid,post_author,post_date,post_title,post_content,post_name,post_modified,post_version,post_type,comment_count,post_veiws');
		$this->db->where('pid', $pid);

		if($this->db->get('posts')->num_rows() == 1) {
			$result = $this->db->get('posts')->row();
			$this->db->flush_cache();

			return $result;
		}
		return 0;
	}

	function get_title($pid) {
		$this->db->start_cache();
		$this->db->where('pid', $pid);
		$this->db->select('pid,post_title,post_name');


		$this->db->flush_cache();

		return $this->db->get('posts')->row();
	}
	function update_veiws($pid,$str='post_veiws') {
		$sql = "UPDATE myh_posts SET ".$str." = ".$str." + 1 WHERE pid = ?";
		$this->db->query($sql, array($pid));
	}

	function insert() {
		$this->load->helper('typography');

		$post['post_title'] = $this->input->post('post_title');
		$post['post_content'] = auto_typography($this->input->post('post_content'), TRUE);
		$post['post_modified'] = $post['post_date'] = date("Y-m-d H:i:s");
		$string = str_split($post['post_content'], 2048);
		//$string = <br />
		$post['post_excerpt'] = $string[0];
		$this->db->insert('posts', $post);

		return $this->db->insert_id();
	}

}

/* End of file post.php */
/* Location: ./application/models/post.php */